package com.example.controller;

import com.example.entity.User;
import com.example.service.UserService;
import com.example.vo.Result;
import com.example.vo.Result1;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api")
@Api(tags = "user测试")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("test1")
    @ApiOperation(value = "查找所有")
    public Result1 findAll() {
        return userService.findAll();
    }

    @GetMapping("test2")
    @ApiOperation(value = "文件抽取")
    public void fileExtraction(HttpServletResponse response, @RequestParam(value = "type", required = false) String type) {
        userService.fileExtraction(response, type);
    }

    @PostMapping("test3")
    @ApiOperation(value = "查找所有")
    public Map<Integer, List<Integer>> test() {

        Map<Integer, List<Integer>> shardingItemAndDataGroupMap = new HashMap<Integer, List<Integer>>();

        //这里进行自定义的数据分组操作
        //TODO 将数据按照一定规则进行数据分组；

        //TODO 获取到数据分组的最大值
        int maxDataGroupNum = 6;

        //TODO 将数据分组与作业分片建立映射关系，并持久化到DB
        //shardingItemAndDataGroupMap ==>  作业分片项，List<数据分组编码>
        for(int i=1;i<=maxDataGroupNum;i++){
            int shardingItemNum = i%3;
            shardingItemAndDataGroupMap.putIfAbsent(shardingItemNum,new ArrayList<Integer>());
            shardingItemAndDataGroupMap.get(shardingItemNum).add(i);
        }

        return shardingItemAndDataGroupMap;
    }





}